#include <iostream>
using namespace std;

typedef long long LL;

const int N = 1e5 + 10;

int n;
LL a[N];

int main()
{
    cin >> n; 
    LL sum = 0;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }

    int left = 1, right = 1;
    LL k = 0;
    LL ret = 0;

    while(right <= n)
    {
        k += a[right];
        while(2 * k >= sum)
        {
            // 用 sum - k 更新结果
            ret = max(ret, sum - k);
            k -= a[left++];
        }
        // 用 k 更新结果
        ret = max(ret, k);
    }
    cout << ret << endl;
    return 0;
}